/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package bean;

import java.io.Serializable;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;
import model.dao.UserDAO;
import model.entity.User;
import model.service.UsersDAOService;

/**
 *
 * @author duy
 */
@ManagedBean
@SessionScoped
public class LoginBean {

    private final UsersDAOService USER_SERVICE = UserDAO.getInstance();
    private User user = new User();

    private String massage = "Det";

    private String username;
    private String password;

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String checkLogin() {
        if (USER_SERVICE.checkLogin(username, password)) {
            HttpSession session = util.Support.getSession();
            User u = UserDAO.getInstance().getusersbyUserName(getUser().getTendangnhap());
            session.setAttribute("tendangnhap", u);
            return "./module/danhsach.jsf";
            
        } else {
            return "./index.jsf";

        }
    }


    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

}
